<?php 
function sendSMS( $data, $model ){
	loadClass('ZSms');
	$model->update('configs',array(
		sms_uid	=> new Model_Expr('`sms_uid`+1')
	));
	$configs = $model->fetchRow("SELECT * FROM `configs` LIMIT 1");
	
	$sms = new ZSms($configs['sms_url'], $configs, 'sms_');
	
	//fix
	$phone = $data['address'];
	if( !preg_match("#^84#is",$phone) ){
		$phone = preg_replace("#^(084|0)#is","84",$phone);
	}
	
	$c = $sms->sendData(array(
		dest		=> $phone,			
		msgbody		=> stripslashes($data['content']),
		reqtime		=> str_replace(' ','',date('Y m d H i s',time())),
		mtseq		=> $configs['sms_uid']
	));	
		
	//die(var_dump($c));	
	$data['status']			= $c->SendMTResult;
	$data['result_send']	= $c->SendMTResult;
	$model->insert('sms',$data);
		
}